package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.security.PermissionUtils;
import com.ruoyi.system.domain.TmdDutyApplication;
import com.ruoyi.system.domain.TmdDutyDatePeople;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.ITmdDutyApplicationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TmdDutyMessage;
import com.ruoyi.system.service.ITmdDutyMessageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新增值班Controller
 * 
 * @author ruoyi
 * @date 2024-04-20
 */
@Controller
@RequestMapping("/system/message")
public class TmdDutyMessageController extends BaseController
{
    private String prefix = "system/message";

    @Autowired
    private ITmdDutyMessageService tmdDutyMessageService;

    @Autowired
    private ITmdDutyApplicationService tmdDutyApplicationService;

    @Autowired
    private ISysDeptService iSysDeptService;

    @RequiresPermissions("system:message:view")
    @GetMapping()
    public String message(Model model)
    {
        Integer i=tmdDutyMessageService.updateAllDate();
        List<SysDept> deptList = iSysDeptService.selectAllDeptList();
        model.addAttribute("deptList",deptList);
        List<TmdDutyApplication> applicationList = tmdDutyApplicationService.getAllApp();
        model.addAttribute("applicationList",applicationList);
        return prefix + "/message";
    }

    /**
     * 查询值班列表
     */
    @RequiresPermissions("system:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TmdDutyMessage tmdDutyMessage)
    {
        startPage();
        Integer i=tmdDutyMessageService.updateAllDate();
        List<TmdDutyMessage> list = tmdDutyMessageService.selectTmdDutyMessageList(tmdDutyMessage);
        return getDataTable(list);
    }

    /**
     * 导出值班列表
     */
    @RequiresPermissions("system:message:export")
    @Log(title = "新增值班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TmdDutyMessage tmdDutyMessage)
    {
        List<TmdDutyMessage> list = tmdDutyMessageService.selectTmdDutyMessageList(tmdDutyMessage);
        ExcelUtil<TmdDutyMessage> util = new ExcelUtil<TmdDutyMessage>(TmdDutyMessage.class);
        return util.exportExcel(list, "新增值班数据");
    }

    /**
     * 新增值班
     */
    @GetMapping("/add")
    public String add(Model model)
    {
        return prefix + "/add";
    }

    /**
     * 新增保存值班
     */
    @RequiresPermissions("system:message:add")
    @Log(title = "新增值班", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TmdDutyMessage tmdDutyMessage)
    {
        tmdDutyMessage.setCreatePerson((String) PermissionUtils.getPrincipalProperty("userName"));
        return toAjax(tmdDutyMessageService.insertTmdDutyMessage(tmdDutyMessage));
    }

    /**
     * 修改值班
     */
    @RequiresPermissions("system:message:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap,Model model)
    {
        TmdDutyMessage tmdDutyMessage = tmdDutyMessageService.selectTmdDutyMessageById(id);
//        mmap.put("tmdDutyMessage", tmdDutyMessage);
        model.addAttribute("tmdDutyMessage", tmdDutyMessage);
        return prefix + "/edit";
    }

    /**
     * 查看值班详情
     */
    @RequiresPermissions("system:message:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap,Model model)
    {
        TmdDutyMessage tmdDutyMessage = tmdDutyMessageService.selectTmdDutyMessageById(id);
        model.addAttribute("tmdDutyMessage", tmdDutyMessage);
        return prefix + "/detail";
    }

    /**
     * 修改保存值班
     */
    @RequiresPermissions("system:message:edit")
    @Log(title = "新增值班", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TmdDutyMessage tmdDutyMessage)
    {
        return toAjax(tmdDutyMessageService.updateTmdDutyMessage(tmdDutyMessage));
    }

    /**
     * 删除值班
     */
    @RequiresPermissions("system:message:remove")
    @Log(title = "新增值班", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tmdDutyMessageService.deleteTmdDutyMessageByIds(ids));
    }
}
